Skip to content

Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments#649

Merged
artursouza merged 48 commits into
dapr:masterfrom
willtsai:loopback-auto-detect-218
Feb 20, 2024
Merged

Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments#649
artursouza merged 48 commits into
dapr:masterfrom
willtsai:loopback-auto-detect-218

Conversation

@willtsai

@willtsai willtsai commented Nov 4, 2021

Copy link
Copy Markdown
Contributor

Description

I've made some changes to move away from hardcoded "127.0.0.1" IP addresses (representing localhost) to make the SDK and Tests compatible with exclusively IPv6 environments:

  • Replaced hardcoded "127.0.0.1" in various URL strings with the SIDECAR_IP property constant
  • Changed the DEFAULT_SIDECAR_IP property constant's value from the hardcoded "127.0.0.1" to instead use the Java API getLoopbackAddress(). This would make the IP default value more dynamic and account for situations where users operate in an exclusively ipv6 environment and the logic ends up falling back to the default value.
  • Added a test util to detect IPv6 addresses and format them accordingly for HTTP URLs using the square brackets representation in unit tests

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #218

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation (N/A)

@willtsai willtsai requested review from a team as code owners November 4, 2021 06:09
@mukundansundar

Copy link
Copy Markdown
Contributor

@artursouza Wasn't there was a particular reason why 127.0.0.1 was used instead of localhost?

@willtsai

Copy link
Copy Markdown
Contributor Author

@artursouza Wasn't there was a particular reason why 127.0.0.1 was used instead of localhost?

@mukundansundar according to #213, it was changed from localhost to 127.0.0.1 "to avoid local OS specific DNS lookups that might hinder performance". My changes here don't reintroduce the use of localhost, but rather uses the dynamically sourced SIDECAR_IP constant from the system.

Comment thread sdk/src/main/java/io/dapr/config/Properties.java Outdated
@willtsai willtsai changed the title Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments [WIP] Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments Nov 13, 2021
@willtsai

willtsai commented Dec 6, 2021

Copy link
Copy Markdown
Contributor Author

Work in progress, please do not merge

@willtsai willtsai changed the title [WIP] Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments Jan 26, 2022
artursouza and others added 20 commits January 25, 2022 16:28
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
* Upgrade okhttp-mock dependency

Version 1.3.2 was never deployed to Maven Central

* No longer refer to JCenter, as it has been shut down

Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.3.1 to 2.4.0.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](actions/setup-java@v2.3.1...v2.4.0)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
* Upgrade Dapr CLI and runtime.

Signed-off-by: Artur Souza <artursouza.ms@outlook.com>

* Fix expected vault output.

Signed-off-by: Artur Souza <artursouza.ms@outlook.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
* Update LICENSE to Apache 2.0

Signed-off-by: Artur Souza <artursouza.ms@outlook.com>

* Update headers to Apache 2.

Signed-off-by: Artur Souza <artursouza.ms@outlook.com>

Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Bumps [actions/github-script](https://github.com/actions/github-script) from 1 to 5.
- [Release notes](https://github.com/actions/github-script/releases)
- [Commits](actions/github-script@v1...v5)

---
updated-dependencies:
- dependency-name: actions/github-script
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Issue reference: dapr/docs#2039

Signed-off-by: Will <william.wl.tsai@gmail.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.4.0 to 2.5.0.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](actions/setup-java@v2.4.0...v2.5.0)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>
* inital draft for config api

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* Introducing new client for preview apis and code refactoring

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* Unit tests and code refactoring

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* Adding integration test

Signed-off-by: pravinpushkar <ppushkar@microsoft.com>

* Copyright changes

Signed-off-by: pravinpushkar <ppushkar@microsoft.com>

* Review comments fixes

Signed-off-by: pravinpushkar <ppushkar@microsoft.com>

* Removed DaprPreviewClientProxy and updated example README

Signed-off-by: pravinpushkar <ppushkar@microsoft.com>

* Adding validate workflow for cofiguration api example

Signed-off-by: pravinpushkar <ppushkar@microsoft.com>

* fixing example autovalidation and code coverage

Signed-off-by: pravinpushkar <ppushkar@microsoft.com>

* Fixing autovalidation and removing getAllConfiguration

Signed-off-by: pravinpushkar <ppushkar@microsoft.com>

* Fixing review comments

Signed-off-by: pravinpushkar <ppushkar@microsoft.com>

* Add regex header checkstyle.

Signed-off-by: Artur Souza <artursouza.ms@outlook.com>

* Fix headers and add javadocs to some.

Signed-off-by: Artur Souza <artursouza.ms@outlook.com>

Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>

@artursouza artursouza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will give another pass tomorrow. Thanks.

Comment thread sdk-actors/pom.xml
Comment thread sdk/pom.xml
Signed-off-by: Will Tsai <william.wl.tsai@gmail.com>

@artursouza artursouza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor change.

* @return The loopback address String
*/
public static String getHostLoopbackAddress() {
return InetAddress.getLoopbackAddress().getHostAddress();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this method automatically return the Ipv6 between "[]"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artursouza Sorry for the delay, finally had some time to look into this. I changed some unit tests locally to validate IPv6 sidecar IP constants contained within "[]" and it seems like your suggestion is viable - for both URL endpoint invocation formats and Dapr client instantiation. Great recommendation!

However, before I proceed, I need to validate an implementation detail with you. To test for whether an address is IPv6, it would be convenient to leverage the Apache Commons Validator, though you have recommended against bringing in 3P libraries beyond the test scope. Is it possible to get an exception for this case, or do I have to write a custom IPv6 validator within NetworkUtils?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@willtsai Is it complex to write a validator for IPv6 ? both standard pattern and hex compressed pattern along with IPv4 validation?
I am wary of adding a new dependency specifically for one validation ....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood - should not be too complex but I wanted to see if the work (and subsequent unit tests) could be avoided. Seems like adding a new dependency is not worth it here, so I'll work on the custom validator.

@willtsai willtsai Jul 12, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started the implementation for this and have a working validator, but then realized that this would introduce inconsistencies into the Property<String> SIDECAR_IP config object since the result would be that the special IPv6 formatting would only get applied when DEFAULT_SIDECAR_IP is used in fallback scenarios, so the IPv6 address would not get "[]" applied to them when they are sourced from the system property name or env variable.

Thus, I think there are two options:

  1. Leave the implementation of adding "[]" to the http address to the client and thus just modifying our test clients accordingly, i.e. code in this PR remain as is.
  2. Make modifications to the Property and/or Properties objects to introduce a new object class IpProperty.java or equivalent that would apply the required IPv6 formatting to the IP address it returns.

@artursouza @mukundansundar - what are your thoughts here? which option would you prefer? (I personally think option 1 introduces less surprises to the client who may not be expecting IPv6 address to be pre-formatted for http URLs)

willtsai and others added 2 commits July 12, 2022 13:29
@cicoyle

cicoyle commented Dec 21, 2023

Copy link
Copy Markdown
Contributor

@willtsai mind resolving the conflicts?

Signed-off-by: Will <28876888+willtsai@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
@willtsai

willtsai commented Jan 2, 2024

Copy link
Copy Markdown
Contributor Author

@willtsai mind resolving the conflicts?

@cicoyle done, though now i need to investigate the test failures...

Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
@willtsai

willtsai commented Jan 4, 2024

Copy link
Copy Markdown
Contributor Author

@cicoyle i've addressed all merge conflicts and test failures, can you please take another look? (i think the build tests just need to be re-run)

@codecov

codecov Bot commented Feb 19, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (14cc3f8) 77.60% compared to head (d9fd2c0) 77.61%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #649   +/-   ##
=========================================
  Coverage     77.60%   77.61%           
- Complexity     1570     1571    +1     
=========================================
  Files           144      144           
  Lines          4765     4767    +2     
  Branches        554      554           
=========================================
+ Hits           3698     3700    +2     
  Misses          781      781           
  Partials        286      286           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cicoyle cicoyle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - nice to see this coming to a closing 🎉

@artursouza artursouza merged commit 57b86c5 into dapr:master Feb 20, 2024
@willtsai

Copy link
Copy Markdown
Contributor Author

woo! thanks @cicoyle @artursouza 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The sdk should auto-detect ipv4 loopback and ipv6 loopback for daprd communication.

8 participants